﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCoreLenarn
{
    public class StudentConfig : IEntityTypeConfiguration<Student>
    {
        public void Configure(EntityTypeBuilder<Student> builder)
        {
            builder.ToTable("T_Student");
            builder.Property(s => s.Name).IsUnicode().HasMaxLength(20);
            // 多对多的关系配置 可用放在任意一方。使用 UsingEntity 配置中间表
            builder.HasMany(s => s.Teachers).WithMany(t => t.Students)
                .UsingEntity(j => j.ToTable("T_Student_Teacher"));
        }
    }

    class TeacherConfig : IEntityTypeConfiguration<Teacher>
    {
        public void Configure(EntityTypeBuilder<Teacher> builder)
        {
            builder.ToTable("T_Teacher");
            builder.Property(t => t.Name).IsUnicode().HasMaxLength(20);
        }
    }
}
